package com.softeem.service.Impl;

import com.softeem.entity.Info;
import com.softeem.entity.WorkOrder;
import com.softeem.mapper.InfoMapper;
import com.softeem.mapper.WorkOrderMapper;
import com.softeem.service.InfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

@Service
public class InfoServiceImpl implements InfoService {

    @Autowired
    private InfoMapper infoMapper;
    @Autowired
    private WorkOrderMapper orderMapper;

    @Override
    @Transactional
    public boolean newInfo(Info info) {
        String state = info.getSenderType();
        WorkOrder order = new WorkOrder();
        order.setId(info.getoId());
        if(state != null && state.equals("1")){       //发送人为用户
            order.setIsUreplay(1);
            order.setIsSreplay(0);
        }else if(state != null && state.equals("2")){ //发送人为客服
            order.setIsUreplay(0);
            order.setIsSreplay(1);
        }
        order.setNowTime(new Date());
        return infoMapper.insertSelective(info) > 0 && orderMapper.updateByPrimaryKeySelective(order) > 0;
    }
}
